<template>
  <div :class="{ 'hidden': hidden }" class="pagination-container">
    <el-pagination
      v-model:current-page="currentPage"
      :background="background"
      :page-size="pageSize"
      :layout="layout"
      :page-sizes="pageSizes"
      :total="total"
      v-bind="$attrs"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>
<script lang="ts" setup>
import { computed } from 'vue'
const prop = defineProps({
  total: {
    required: true,
    type: Number
  },
  page: {
    type: Number,
    default: 1
  },
  limit: {
    type: Number,
    default: 10
  },
  pageSizes: {
    type: Array,
    default() {
      return [10, 20, 30, 50]
    }
  },
  layout: {
    type: String,
    default: 'total, sizes, prev, pager, next, jumper'
  },
  background: {
    type: Boolean,
    default: true
  },
  autoScroll: {
    type: Boolean,
    default: true
  },
  hidden: {
    type: Boolean,
    default: false
  }
})
const emit = defineEmits(['pagination', 'update:page', 'update:limit'])

const handleSizeChange = (val: number) => {
  emit('pagination', { page: currentPage, limit: val })
  // if (this.autoScroll) {
  //   scrollTo(0, 800)
  // }
}
const handleCurrentChange = (val: number) => {
  emit('pagination', { page: val, limit: pageSize })
  // if (this.autoScroll) {
  //   scrollTo(0, 800)
  // }
}
const currentPage = computed({
  get: () => prop.page,
  set: val => {
    emit('update:page', val)
  }
})
const pageSize = computed({
  get: () => prop.limit,
  set: val => {
    emit('update:limit', val)
  }
})
</script>

<style scoped>
::v-deep(.el-input__inner) {
  height: 28px;
  width: 100px;
}
.pagination-container {
  float: right;
  background: #fff;
  padding: 16px 16px;
}
.pagination-container.hidden {
  display: none;
}
</style>
